
package com.tom.commonframework.common.refreshview;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;

import com.tom.commonframework.common.refreshview.base.RefreshLayoutBase;
import com.tom.commonframework.common.refreshview.enums.RefreshViewStatus;


public class RefreshRecyclerView extends RefreshLayoutBase<XRecyclerView> implements XRecyclerView.OnScrollToBottomListener {



    public RefreshRecyclerView(Context context) {
        this(context, null);
    }

    /**
     * @param context
     * @param attrs
     */
    public RefreshRecyclerView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RefreshRecyclerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void setupContentView(Context context) {
        mContentView = new XRecyclerView(context,attrs);
        mContentView.setOnScrollToBottomListener(this);
        // 开启可点击,使得onTouchEvent在处理触摸事件时返回true
//        mContentView.setClickable(true);
    }


    @Override
    protected void onRestoreInstanceState(Parcelable state) {
        try {
            super.onRestoreInstanceState(state);
        } catch (Exception e) {
            e.printStackTrace();
        }
        state = null;
    }

    @Override
    protected boolean isTop() {
        return (!ViewCompat.canScrollVertically(mContentView, -1));
    }

    @Override
    protected boolean isBottom() {
        return false;
    }


    @Override
    public boolean isScrollToBottom() {
        return mCurrentStatus == RefreshViewStatus.STATUS_IDLE
                && mScroller.getCurrY() <= mInitScrollY
                && mYOffset <= 0;
    }

    @Override
    public void onScrollToBottom() {
        doLoadMore();
    }


}
